package com.againstsky.algorithm.sort;

import com.againstsky.algorithm.bean.Person;
import com.againstsky.algorithm.bean.SortBase;

/**
 * Created by agasinst on 2017/8/25.
 */

//选择排序算法交换次数为N，比较次数为N*N/2
//比较和交换次数不受原始数据排列影响
public class Selection extends SortBase {
    @Override
    public void sort(Comparable[] a) {
        int N=a.length;
        for (int i = 0; i < N; i++) {
            int min =i;
            for (int j = i+1; j < N; j++) {
                if(less(a[j],a[min])) min=j;
            }
            exch(a,i,min);
        }
    }

}
